# ------------------------------
# 3. Pydantic模型 (数据验证和序列化)
#    成绩表(Score)相关模型
# ------------------------------
from datetime import datetime, date
from typing import Literal, Annotated, Optional, List
from pydantic import BaseModel, Field, validator, AfterValidator
from sqlalchemy import Enum
from day20.schema.schema_stu import StuSchema


class ScoreSchema(BaseModel):
    """成绩表基础模型，包含公共字段"""

    stu_id: int = Field(..., gt=0, description="学生编号（外键关联stu表）")
    # 学生姓名：1-20个字符
    stu_name: Optional[str] = Field(None, min_length=1, max_length=20, description="学生姓名")
    # 学生班级：字符串，1-20个字符
    class_name: Optional[str] = Field(None, min_length=1, max_length=20, description="学生班级")

    assessment_sequence: int = Field(..., ge=1, description="考核序次（正整数）")
    mark: Optional[int] = Field(None, ge=0, le=100, description="分数（0-100分）")

class ScoreCreateSchema(ScoreSchema):
    """创建成绩模型：外键stu_id必填"""
    pass

class ScoreUpdateSchema(BaseModel):
    """更新成绩模型：所有字段均为可选"""
    stu_name: Optional[str] = Field(None, min_length=1, max_length=20, description="学生姓名")

    class_name: Optional[str] = Field(None, min_length=1, max_length=20, description="学生班级")

    assessment_sequence: Optional[int] = Field(None, ge=1, description="考核序次（正整数）")

    mark: Optional[int] = Field(None, ge=0, le=100, description="分数（0-100分）")

class ScoreResponseSchema(ScoreSchema):
    """成绩响应模型：包含自增主键和关联的学生信息"""
    id: int = Field(..., description="自增序号（主键）")
    class Config:
        from_attributes = True


